﻿using Infrastructure.Attribute;
using Microsoft.Extensions.DependencyInjection;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using ZR.Model.mes.md;
using ZR.Model.mes.md.DTO;
using ZR.Service.mes.md.IService;
using static Org.BouncyCastle.Crypto.Engines.SM2Engine;

namespace ZR.Service.mes.md
{
    [AppService(ServiceType = typeof(IMdWorkshopService), ServiceLifetime = LifeTime.Transient)]
    public class MdWorkshopService : BaseService<MdWorkshop>, IMdWorkshopService
    {
        public int AddWorkshop(MdWorkshop workshop)
        {
            return Add(workshop);


        }

        public int deleteWorkshop(int[] ids)
        {
            return Delete(ids);
        }

        public (int, List<MdWorkshop>) GetAll(string workshopId, string workshopName, string workshopPosition, int pageNum, int pageSize)
        {
            int totalNum = 0;
            var predicate = Expressionable.Create<MdWorkshop>()
                .AndIF(!string.IsNullOrEmpty(workshopId), it => it.WorkshopId.Contains(workshopId))
                .AndIF(!string.IsNullOrEmpty(workshopName), it => it.WorkshopName.Contains(workshopName))
                .AndIF(!string.IsNullOrEmpty(workshopPosition), it => it.WorkshopPosition.Contains(workshopPosition))
                .ToExpression();


            List<MdWorkshop> data = Context.Queryable<MdWorkshop>().Where(predicate).ToPageList(pageNum, pageSize, ref totalNum);

            return (totalNum, data);
        }

        public int UpdateWorkshop(MdWorkshop workshop)
        {
            return Update(workshop, true);
        }
      
    }
}
